home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / ENTRPRIS / APE / AELOGGER / LOGGER.CLS < prev    next >
Encoding:
Visual Basic class definition  |  1996-12-04  |  8.5 KB  |  203 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Logger"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Attribute VB_Description = "During APE tests, logs event and error records for later retrieval."
  11. Option Explicit
  12. '-------------------------------------------------------------------------
  13. 'This is the only public class in this application.  See modLogger for
  14. 'purpose.
  15. '-------------------------------------------------------------------------
  16.  
  17. '*****************
  18. 'Public Properties
  19. '*****************
  20.  
  21. Public Property Let Show(ByVal bShow As Boolean)
  22. Attribute Show.VB_Description = "Determines whether the Logger shows a form."
  23.     '-------------------------------------------------------------------------
  24.     'Purpose:   Show property determines whether or not a form is displayed
  25.     '           while the logger is loaded.
  26.     '
  27.     'Effects:   [gbShowForm]
  28.     '               Becomes equal to the passed parameter
  29.     '           [frmLogger]
  30.     '               Becomes loaded and visible if parameter is true, but is
  31.     '               unloaded if parameter is false
  32.     '-------------------------------------------------------------------------
  33.     If Not gbShowForm = bShow Then
  34.         gbShowForm = bShow
  35.         If bShow = True Then
  36.             frmLogger.Show
  37.         Else
  38.             Unload frmLogger
  39.         End If
  40.     End If
  41. End Property
  42.  
  43. Public Property Get Show() As Boolean
  44.     Show = gbShowForm
  45. End Property
  46.  
  47. Public Property Let AutomaticWrite(ByVal bWrite As Boolean)
  48. Attribute AutomaticWrite.VB_Description = "Determines whether log records are written to a file and purged from memory when the log threshold is reached."
  49.     '-------------------------------------------------------------------------
  50.     'Purpose:   AutomaticWrite property determines if the Logger should
  51.     '           automatically write to a file when a record threshold is met.
  52.     'Effects:   [gbWriteRecords]
  53.     '               Becomes equal to the passed parameter
  54.     '-------------------------------------------------------------------------
  55.     gbWriteRecords = bWrite
  56. End Property
  57.  
  58. Public Property Get AutomaticWrite() As Boolean
  59.     AutomaticWrite = gbWriteRecords
  60. End Property
  61.  
  62. Public Property Let Threshold(ByVal lThreshold As Long)
  63. Attribute Threshold.VB_Description = "Sets the log threshold in kilobytes that determines when log records are written to a file and purged from memory."
  64.     '-------------------------------------------------------------------------
  65.     'Purpose:   If AutomaticWrite property is true, logger uses the
  66.     '           Threshold property to determine how many kilobytes should
  67.     '           be held in memory before writing to a file and emptying
  68.     '           log record array.
  69.     'Effects:   [glThreshold]
  70.     '               Becomes equal to the passed parameter
  71.     '           [glThresholdRecs]
  72.     '               Becomes an estimated number of records equivalent
  73.     '-------------------------------------------------------------------------
  74.     On Error Resume Next
  75.     glThreshold = lThreshold
  76.     glThresholdRecs = lThreshold * giLOG_RECORD_KILOBYTES
  77. End Property
  78.  
  79. Public Property Get Threshold() As Long
  80.     Threshold = glThreshold
  81. End Property
  82.  
  83. '************************
  84. 'Public Methods
  85. '************************
  86.  
  87. Public Sub SetProperties(ByVal bShow As Boolean, Optional ByVal bAutomaticWrite As Variant, Optional ByVal lThreshold As Variant)
  88. Attribute SetProperties.VB_Description = "Sets all Logger properties in one method call."
  89.     '-------------------------------------------------------------------------
  90.     'Purpose:   Provided so that properties can be set by one method call
  91.     'Effects:   Sets the following properties:
  92.     '           Show, AutomaticWrite, Threshold
  93.     '-------------------------------------------------------------------------
  94.     Me.Show = bShow
  95.     If Not IsMissing(bAutomaticWrite) Then gbWriteRecords = bAutomaticWrite
  96.     If Not IsMissing(lThreshold) Then Me.Threshold = lThreshold
  97. End Sub
  98.  
  99. Public Sub Record(ByVal sComponent As String, ByVal lServiceID As Long, ByVal sComment As String, ByVal lMilliseconds As Long)
  100. Attribute Record.VB_Description = "Adds a log record."
  101.     '-------------------------------------------------------------------------
  102.     'Purpose:   Provided for any app to call to add one log record
  103.     'Effects:   Calls AddLogRecord
  104.     '           Calls WriteRecords when the Threshold is reached
  105.     '-------------------------------------------------------------------------
  106.     AddLogRecord sComponent, lServiceID, sComment, lMilliseconds
  107.     If gbWriteRecords Then
  108.         If glLastAddedRecord >= glThresholdRecs And glThresholdRecs > 0 Then
  109.             WriteRecords
  110.         End If
  111.     End If
  112. End Sub
  113.  
  114. Public Function GetRecords() As Variant
  115. Attribute GetRecords.VB_Description = "Returns a variant array containing log records.  Must be called multiple times until until Null is returned."
  116.     '-------------------------------------------------------------------------
  117.     'Purpose:   Use to retrieve all of the log records passed to the Logger
  118.     '           Keep calling until, it returns does not return a variant array
  119.     'Return:    Returns a two dimension array in which
  120.     '           the first four elements of the first dimension
  121.     '           are Component(string), ServiceID(Long),Comment(string),
  122.     '           and Milliseconds(long) respectively
  123.     '           the second dimension represents the number of log records
  124.     '           User Defined Types can not be returned from public
  125.     '           procedures of public classes
  126.     'Effects:   [gaRecords]
  127.     '               Redimensioned after calling GetRecords to not have empty
  128.     '               records at the end
  129.     '           [glLastAddedRecord]
  130.     '               becomes equal to giNO_RECORDS
  131.     '-------------------------------------------------------------------------
  132.     
  133.     GetWrittenLog
  134.     'Trim the array to only send the filled elements
  135.     If glLastAddedRecord >= 0 Then
  136.         If UBound(gaRecords, 2) <> glLastAddedRecord Then ReDim Preserve gaRecords(giLOG_ARRAY_DIMENSION_ONE, glLastAddedRecord)
  137.         GetRecords = gaRecords()
  138.         'Changing the glLastAddedRecord flag to giNO_RECORDS causes
  139.         'WriteRecords to ignore records at next call
  140.         glLastAddedRecord = giNO_RECORDS
  141.     Else
  142.         GetRecords = Null
  143.     End If
  144. End Function
  145.  
  146. '*******************
  147. 'Private Procedures
  148. '*******************
  149.  
  150. Private Sub Class_Initialize()
  151.     '-------------------------------------------------------------------------
  152.     'Purpose:   Set the initial state of the logger when the first logger
  153.     '           class object is initialized
  154.     'Effects:   [glInstances]
  155.     '               Iterates it once
  156.     '-------------------------------------------------------------------------
  157.     'Count how many times this class is instanced
  158.     'to react to the first instance or the release
  159.     'of the last instance.
  160.     glInstances = glInstances + 1
  161.     If glInstances = 1 Then
  162.        'Set default property values
  163.        gbShowForm = gbSHOW_FORM_DEFAULT
  164.        gbWriteRecords = gbWRITE_RECORDS_DEFAULT
  165.        Me.Threshold = gbTHRESHOLD_DEFAULT
  166.        gsFileName = GetTempFile
  167.        glLastAddedRecord = giNO_RECORDS
  168.        'Load frmLogger if gbShowForm is True
  169.        If gbShowForm Then frmLogger.Show
  170.     End If
  171. End Sub
  172.  
  173. Private Sub Class_Terminate()
  174.     '-------------------------------------------------------------------------
  175.     'Purpose:   Closes the form and destroys the tempfile when the last
  176.     '           instance is terminated
  177.     'Effects:   [glInstances]
  178.     '               decreases by one
  179.     '-------------------------------------------------------------------------
  180.     'Count how many times this class is instanced
  181.     'so subtract one every terminate event
  182.     'If the last terminate event is occuring
  183.     'make sure forms are unloaded and write records
  184.     On Error GoTo Class_TerminateError
  185.     glInstances = glInstances - 1
  186.     If glInstances = 0 Then
  187.         Unload frmLogger
  188.         Close   'Close here incase getting logs got canceled
  189.         Kill gsFileName
  190.     End If
  191.     Exit Sub
  192. Class_TerminateError:
  193.     Select Case Err.Number
  194.         Case ERR_FILE_NOT_FOUND
  195.             'There is no file to kill
  196.             Resume Next
  197.         Case Else
  198.             Resume Next
  199.     End Select
  200. End Sub
  201.  
  202.  
  203.